﻿using System;
using System.Configuration;
using DocumentManager.Abstractions;
using DocumentManager.Abstractions.Interfaces.Helpers;
using DocumentManager.Enums;
using Path = System.IO.Path;

namespace DocumentManager.Helpers
{
	public class ApplicationConfiguration : ApplicationBaseConfiguration, IApplicationConfiguration
	{
		#region ApplicationBaseConfiguration Members

		public override string Get(string parameterName)
		{
			if (string.IsNullOrWhiteSpace(parameterName))
				return string.Empty;

			return Manager.AppSettings.Settings[parameterName].Value ?? string.Empty;
		}

		public override void Set(string value, string parameterName)
		{
			if (string.IsNullOrWhiteSpace(parameterName))
				return;

			Manager.AppSettings.Settings[parameterName].Value = value ?? string.Empty;
			Manager.Save(ConfigurationSaveMode.Minimal);
		}

		#endregion

		#region IApplicationConfiguration Members

		public string Performer
		{
			get { return Get("Performer"); }
			set { Set(value, "Performer"); }
		}

		public string Director
		{
			get { return Get("Director"); }
			set { Set(value, "Director"); }
		}

		public string TempOrderDocumentName
		{
			get { return Get("TempOrderDocumentName"); }
			set { Set(value, "TempOrderDocumentName"); }
		}

		public string LogOrdersTemplateFilePath
		{
			get { return Get("LogOrdersTemplateFilePath"); }
			set { Set(value, "LogOrdersTemplateFilePath"); }
		}

		public string GetOrderTemplateFilePathByOrderType(OrderType orderType)
		{
			string result;

			switch (orderType)
			{
				case OrderType.Leave:
					result = Get("LeaveOrderTemplateFilePath");
					break;

				case OrderType.Dismissal:
					result = Get("DismissalOrderTemplateFilePath");
					break;

				case OrderType.BusinessTrip:
					result = Get("BusinessTripOrderTemplateFilePath");
					break;

				default:
					throw new NotImplementedException(string.Format("not implemented this order type"));
			}

			return Path.Combine(Environment.CurrentDirectory, result);
		}

		#endregion
	}
}
